<template>
  <div class="header">
    <div class="logo"><img src="../assets/logo.png" alt="logo"></div>
    <div class="btns">
      <button class="wallet" @click="handleConnectWallet" style="width: 100px;">{{ viewAddress === '' ? addressTips : viewAddress }}</button>
      <button class="lang">語言</button>
    </div>
    <TipModal ref="tip" modal-type="b"></TipModal>
  </div>
</template>

<script>
import TipModal from "@/components/TipModal.vue";
import { mapGetters } from "vuex";
import cfxtool from '@/util/cfxpool'
export default {
  name: "Header",
  computed: {
    ...mapGetters([
      'cfxToolInit',
      'viewAddress'
    ])
  },
  data() {
    return {
      addressTips: '連接錢包'
    }
  },
  components: {
    TipModal
  },
  methods: {
    async handleConnectWallet() {
      this.$refs.tip.open()
      if (!this.cfxToolInit) {
        console.log('cfxTool未初始化完成')
        return
      }
      const address = await cfxtool.getAccount()
      const head = address.slice(0, 6)
      const tail = address.slice(address.length - 4)
      const viewAddress = head + '....' + tail
      this.$store.dispatch('app/setAddress', address)
      this.$store.dispatch('app/setViewAddress', viewAddress)
    },
  }
}
</script>

<style scoped lang="less">
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 95px;
  padding: 62px 15px 0 15px;
  background: #000;
  border-radius: 0px 0px 15px 15px;
  opacity: 1;
  box-sizing: border-box;
  /* 紫色渐变 */
  border-width: 2px 0px 0px 0px;
  border-style: solid;
  border-image: linear-gradient(220deg, #9C27B0 94%, #E1BEE7 128%) 2 0 0 0;

  .logo {
    width: 64px;
    height: 20px;

    img {
      display: block;
      max-width: 100%;
    }
  }

  .btns {
    button {
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      width: 73px;
      color: #1e1e1e;

    }
  }

  .wallet {
    border-radius: 20px;
    background: #FFA000;
  }

  .lang {
    margin-left: 10px;
    border: 1px solid #B45CC4;
    background: #fff;
    //border-image: linear-gradient(209deg, #9C27B0 76%, #E1BEE7 122%) 1;
    border-radius: 48px;
  }
}</style>